package com.miniot.base.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miniot.base.entity.Brand;
import com.miniot.base.entity.Devotion;
import com.miniot.base.mapper.BrandMapper;
import com.miniot.base.service.BrandService;
import com.miniot.base.service.DevotionService;
import com.miniot.base.dto.GetLodoDTO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 品牌表
 *
 * @author zzq
 * @date 2023-10-17 11:15:39
 */
@Service
@AllArgsConstructor
@Slf4j
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    private final DevotionService devotionService;
    @Override
    public boolean removeBrandById(Long id) {
        if (ObjectUtil.isEmpty(id)) {
            throw new RuntimeException("id不能为空");
        }
        List<Devotion> list = devotionService.list(new LambdaQueryWrapper<Devotion>().eq(Devotion::getBrandId, id));
        if (list.size()>0) {
            throw new RuntimeException("该投入品正在使用,不能删除");
        }
        this.removeById(id);
        return true;
    }


}
